package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.SkuSaleAttrValue;
import com.atguigu.gmall.product.mapper.SkuSaleAttrValueMapper;
import com.atguigu.gmall.product.service.SkuSaleAttrValueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SkuSaleAttrValueServiceImpl extends ServiceImpl<SkuSaleAttrValueMapper, SkuSaleAttrValue> implements SkuSaleAttrValueService {
    @Autowired
    private SkuSaleAttrValueMapper skuSaleAttrValueMapper;

    @Override
    public Map<String,Long> getSkuValueIdsMap(Long spuId) {
        List<Map<Object, Object>> skuAttrMap = skuSaleAttrValueMapper.getSkuValueIdsMap(spuId);
        Map<String, Long> valueMap = new HashMap<>();
        for (Map<Object, Object> objectObjectMap : skuAttrMap) {
            Long sku_id = (Long)objectObjectMap.get("sku_id");
            String value_map = (String)objectObjectMap.get("value_map");
            valueMap.put(value_map, sku_id);
        }
        return valueMap;

    }
}
